home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: Problem with stringco
- X-Nntp-Posting-Host: golden.ripco.com
- Message-ID: <DKw0DA.I0G@rci.ripco.com>
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Tue, 9 Jan 1996 00:07:58 GMT
- X-Ident-Sender: mambuhl
-
- amundt@pvv.unit.no (Amund Tveit)
- in <yewvimppjz5.fsf@hyll.idt.unit.no> wrote:
-
- >You can try something like this :
- >char *Stringcopy(char *source, int startpos, size_t length)
- >{
- > char tmpstring[SIZEBIGENOUGH];
- > strncpy((char *)(source+startpos),tmpstring,length);
- > return tmpstring;
- >}
-
- >This function is untried but I'll guess it will work (after maybe some
- >change in the casting).
-
- This is not a good idea. Even after changing the strncpy call (assuming
- string.h has been included and that SIZEBIGENOUGH is) to
-
- strncpy(tmpstring, source+startpos, length);
-
- this code will still not work. You are attempting to return a local
- automatic array. tmpstring will point to memory no longer allocated,
- and quite possibly corrupted.
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-